<template>
<div :key="componentKey">
 <vol-box
    :lazy="true"
    v-model="model"
    title="应收账款-销司-导入"
    :height="400"
    :width="700"
    :padding="5"
    :onModelClose="onModelClose"
  >
    <div style="display: flex">
        <div class="block">
            <span class="demonstration"><span style="color:red;">*</span>请选择年月：</span>
              <el-date-picker
                v-model="yearandmonth"
                type="month"
            placeholder="选择月">
            </el-date-picker>
        </div>
        <div style="color:red; padding-top:5px;" >
          &nbsp;&nbsp;&nbsp;&nbsp;注意：重复导入后会覆盖当前所选月份数据。
        </div>
    </div><br>
    <UploadExcel
      :url="url"
      :template="template"
      :importExcelBefore="importExcelBefore"
      :addExtraParameter="addExtraParameter"
    ></UploadExcel>
</vol-box>
</div>
</template>
<script>
    import VolBox from "@/components/basic/VolBox.vue";
    import moment from "moment/moment";
    import UploadExcel from "@/components/basic/UploadExcelFinance.vue";
export default {
  components: {
    'vol-box': VolBox ,
    UploadExcel
  },
  data() {
    return {
      url: "api/cwXSYszk/import1", //导入的路径 
      template: { //下载模板的配置
        url: this.http.ipAddress+"api/cwXSYszk/DownLoadTemplate1",//下载模板的路径 
        fileName: "应收账款-销司", //模板的文件名
      },
      model: false,
      yearandmonth: "", 
    };
  },
  methods: {
    openModel() {
      this.model = true;
    },
    importExcelBefore(formData) { //点击上传时，将其他参数提交到后台
      if(this.yearandmonth ==''||this.yearandmonth==null){
          this.$Message.info("请选择年月！");
          return;
      }
      formData.append("yearandmonth", moment(this.yearandmonth).format("yyyy-MM"));
      return true;
    },
    addExtraParameter(formData) { //点击上传时，将其他参数提交到后台
      if(this.yearandmonth ==''||this.yearandmonth==null){
          this.$Message.info("请选择年月！");
          return;
      }
      formData.append("yearandmonth", moment(this.yearandmonth).format("yyyy-MM"));
      formData.append("addExtraParameterStatus", true);
      return true;
    },
    onModelClose(){
      this.$emit('parentCall', $parent => { $parent.refresh() });
      this.componentKey++;
    },
  },
};
</script>